<template>
    <div class="page">
        <nav-bar>
            <!-- 具名插槽 -->
            <template #left>
                <div class="lefts">
                    <van-icon name="arrow-left" @click="$router.go(-1)"></van-icon>
                </div>
            </template>
            <template #center>
                <div>
                    添加收货地址
                </div>
            </template>
        </nav-bar>
        <div>
            <van-form>
                <van-field v-model="username" name="用户名" label="联系人" placeholder="你的名字"></van-field>
                <van-field name="radio" label=" ">
                    <template #input>
                        <van-radio-group v-model="sex" direction="horizontal">
                            <van-radio name="1">先生</van-radio>
                            <van-radio name="2">女士</van-radio>
                        </van-radio-group>
                    </template>
                </van-field>
                <van-field v-model="phone" label="联系电话" placeholder="你的手机号"></van-field>
                <van-field v-model="address" label="送餐地址" placeholder="小区/写字楼/学校等" readonly @click="$router.push('/search/address')"></van-field>
                <van-field v-model="address_detail" label=" " placeholder="详细地址（如门牌号等）"></van-field>
                <van-field v-model="tag" label="标签" placeholder="无/家/学校/公司"></van-field>
                <div style="margin: 20px;">
                    <van-button color="#4cd964" block @click = "send">确定</van-button>
                </div>
            </van-form>
        </div>
    </div>
</template>
<script>
import { addRess } from '@/api/login'
export default {
        data() {
            return {
                username:"",
                sex:"1",
                phone:"",
                address:"",
                address_detail:"",
                tag:""
            }
        },
        created(){
            if(this.$store.state.city){
                this.address = this.$store.state.city.name
            }
        },
        methods:{
            async send(){
            let obj = {
                user_id:this.user_id,
                address:this.address,
                address_detail:this.address_detail,
                geohash:this.$store.state.geohash,
                name:this.username,
                phone:this.phone,
                tag:this.tag,
                sex:this.sex,
                phone_bk:this.phone_bk,
                tag_type:2
            }
            let res = await addRess(this.$store.state.userId,obj);
            
            console.log(res)
        }
        }
        
}
</script>